import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.HashMap;


public class BDMTotals {
	
	public static void main(String[] args) throws Exception {
		String path = "D:/DataSets/BDMAux.txt";
		HashMap<String, Integer> bdm = new HashMap<String, Integer>();
		FileReader reader = new FileReader(new File(path));
		BufferedReader input = new BufferedReader(reader);
		String line = input.readLine();  
		while(line != null) {
			String key = line.substring(0, 3);
			Integer value = Integer.parseInt(line.substring(line.lastIndexOf("\t")+1, line.length()));
			Integer tmpValue = bdm.get(key);
			if (tmpValue == null){
				bdm.put(key, value);
			}
			else {
				bdm.put(key, value + tmpValue);
			}
			line = input.readLine();
		}
		input.close();  
		reader.close();
		
		String pathOut = "D:/DataSets/BDM.txt";
		FileWriter writer = new FileWriter(new File(pathOut));
		PrintWriter output = new PrintWriter(writer);
		
		Object[] keys = bdm.keySet().toArray();
		for (Object tmpKey : keys) {
			output.println(tmpKey + ".0\t" + bdm.get(tmpKey));
		}
		
		output.close();  
		writer.close(); 
	}
}
